package cn.xzqwjw.taskmanager.security.handler;

import cn.xzqwjw.taskmanager.common.customEnum.ResponseCodeEnum;
import cn.xzqwjw.taskmanager.domain.vo.ResponseVo;
import cn.xzqwjw.taskmanager.utils.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author rush
 */
@Component
public class ValidateCodeImageFailedHandler implements AuthenticationFailureHandler {

  @Override
  public void onAuthenticationFailure(HttpServletRequest request,
                                      HttpServletResponse response,
                                      AuthenticationException exception) {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    String code = ResponseCodeEnum.BAD_REQUEST.getStatusCode();
    String message = "验证码错误！";
    ResponseUtil.writeJson(response, ResponseVo.error(code, message));
  }

}
